/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ticketmaster.dao;

import java.sql.*;
import javax.sql.*;
import java.util.*;
import java.util.logging.*;
import ticketmaster.dataobject.TicketRate;
/**
 *
 * @author Xiaolong Xue
 */
public class TicketRateDAO extends BaseEntityDAO
{
    public TicketRateDAO()
    {
        
    }

     /**
     * Insert ticketRate into database
     * @param ticketRate the new ticketRate entity to be inserted
     * @return newly created tickerRate ID or a 0 on error
     */
    public int insertTicketRate(TicketRate ticketRate)
    {
        return save(ticketRate);
    }

     /**
     * Delete ticketRate that matches the supplied criteria
     * @param ticketRate the supplied criteria
     * @return true on success, false on failure
     */
    public boolean deleteTicketRate(TicketRate ticketRate)
    {
        return delete(ticketRate);
    }

    /**
     * Update the ticketRate using data from the TicketRate Data Object
     * @param ticketRate the ticketRate Data Object to be updated
     * @return true on success, false on failure or error
     */
    public boolean updateTicketRate(TicketRate ticketRate)
    {
        if(   ticketRate.getEventID() == 0
           || ticketRate.getVenueID() == 0
           || ticketRate.getSeatCategoryID() == 0)
            return false;

        return update(ticketRate);
    }

    /**
     * Get the ticketRate that matches the supplied criteria
     * @param ticketRate the supplied criteria
     * @return a TicketRate Data Object if found, or null on error or if not found
     */
    public TicketRate findTicketRate(TicketRate ticketRate)
    {
        String sql = null;
        if(   ticketRate.getEventID() == 0
           || ticketRate.getVenueID() == 0
           || ticketRate.getSeatCategoryID() == 0)
            return null;
        else
            sql = buildQuerySQL(ticketRate);

        RowSet trs = query(sql);
        try
        {
            trs.next();
        }
        catch(SQLException ex)
        {
            Logger.getLogger(TicketRateDAO.class.getName()).log(Level.SEVERE, null, ex);
        }

        return (TicketRate) this.getObject(trs, ticketRate);
    }

     /**
     * Get all ticketRate that match the supplied criteria
     * @param ticketRate supplied criteria
     * @return a RowSet
     */
    public RowSet getTicketRateRowSet(TicketRate ticketRate)
    {
       String sql = buildQuerySQL(ticketRate);
       return query(sql);
    }

    /**
     * Get all ticketRate that match the supplied criteria
     * @param ticketRate supplied criteria
     * @return a collection of TicketRate Data Objects
     */
    public Collection<TicketRate> getTicketRateDO(TicketRate ticketRate)
    {
        String sql = buildQuerySQL(ticketRate);
        RowSet trs = query(sql);
        Collection<TicketRate> ticketRates = new ArrayList<TicketRate>();
        try
        {
            while(trs.next())
            {
                TicketRate ticketRateDO = (TicketRate) this.getObject(trs, ticketRate);
                TicketRate ticketRateItem = new TicketRate();
                ticketRateItem.setEventID(ticketRateDO.getEventID());
                ticketRateItem.setPrice(ticketRateDO.getPrice());
                ticketRateItem.setSeatCategoryID(ticketRateDO.getSeatCategoryID());
                ticketRateItem.setVenueID(ticketRateDO.getVenueID());
                ticketRates.add(ticketRateItem);
            }
        }
        catch(SQLException ex)
        {
            Logger.getLogger(TicketRateDAO.class.getName()).log(Level.SEVERE, null, ex);
        }

        return ticketRates;
    }
}